home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Programming / LEDA / prog / graphics / event.c < prev    next >
C/C++ Source or Header  |  1994-08-05  |  1KB  |  59 lines

  1. #include <LEDA/window.h>
  2. #include <math.h>
  3.  
  4. // this program demonstrates the use of the "read_event" operation
  5.  
  6. main()
  7. {
  8.   window W;
  9.  
  10.   W.set_mode(xor_mode);
  11.  
  12.   int    key;
  13.   double x,y,x0,x1,y0,y1,r1;
  14.  
  15.   for(;;)
  16.   { 
  17.     int b = W.read_mouse(x0,y0);   // read start corner (x0,y0)
  18.  
  19.     if (b == 3) break;  
  20.   
  21.     x1 = x0;
  22.     y1 = y0;
  23.     r1 = 0;
  24.   
  25.     if (b == 1)
  26.     { // while button is down draw rectangle from (x0,y0) 
  27.       // to current mouse position 
  28.  
  29.       while (W.read_event(key,x,y) != button_release_event) 
  30.       { 
  31.         W.draw_rectangle(x0,y0,x1,y1,blue);  // erase old rectangle (xor_mode!)
  32.         W.draw_rectangle(x0,y0,x,y,blue);    // draw new rectangle
  33.         x1 = x;
  34.         y1 = y;
  35.        }
  36.      }
  37.  
  38.  
  39.     if (b == 2)
  40.     { // while button is down draw circle with center (x0,y0) 
  41.       // to current mouse position 
  42.     
  43.       while (W.read_event(key,x,y) != button_release_event) 
  44.       { 
  45.         double r = hypot(x1-x0,y1-y0);
  46.         W.draw_circle(x0,y0,r1,red);  // erase old circle (xor_mode!)
  47.         W.draw_circle(x0,y0,r,red);    // draw new circle
  48.         x1 = x;
  49.         y1 = y;
  50.         r1 = r;
  51.        }
  52.      }
  53.  
  54.   
  55.    }
  56.  
  57.   return 0;
  58. }
  59.